package com.ruoyi.model.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.ModelDetails;
import com.ruoyi.model.service.IModelDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型明细Controller
 * 
 * @author weihanqiang
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/model/modelDetail")
public class ModelDetailsController extends BaseController
{
    @Autowired
    private IModelDetailsService modelDetailsService;

    /**
     * 查询模型明细列表
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelDetails modelDetails)
    {
        startPage();
        List<ModelDetails> list = modelDetailsService.selectModelDetailsList(modelDetails);
        return getDataTable(list);
    }

    /**
     * 导出模型明细列表
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:export')")
    @Log(title = "模型明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelDetails modelDetails)
    {
        List<ModelDetails> list = modelDetailsService.selectModelDetailsList(modelDetails);
        ExcelUtil<ModelDetails> util = new ExcelUtil<ModelDetails>(ModelDetails.class);
        util.exportExcel(response, list, "模型明细数据");
    }

    /**
     * 获取模型明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:query')")
    @GetMapping(value = "/{modeldId}")
    public AjaxResult getInfo(@PathVariable("modeldId") Long modeldId)
    {
        return success(modelDetailsService.selectModelDetailsByModeldId(modeldId));
    }

    /**
     * 新增模型明细
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:add')")
    @Log(title = "模型明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModelDetails modelDetails)
    {
        modelDetails.setCreator(getUsername());
        modelDetails.setCreatorId(getUserId());
        return toAjax(modelDetailsService.insertModelDetails(modelDetails));
    }

    /**
     * 修改模型明细
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:edit')")
    @Log(title = "模型明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModelDetails modelDetails)
    {
        return toAjax(modelDetailsService.updateModelDetails(modelDetails));
    }

    /**
     * 删除模型明细
     */
    @PreAuthorize("@ss.hasPermi('model:modelDetail:remove')")
    @Log(title = "模型明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modeldIds}")
    public AjaxResult remove(@PathVariable Long[] modeldIds)
    {
        return toAjax(modelDetailsService.deleteModelDetailsByModeldIds(modeldIds));
    }
}
